//
//  TableViewCellOfTwo.m
//  UI_Project_A
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 GH. All rights reserved.
//

#import "TableViewCellOfTwo.h"
#import "PictureModel.h"
#import <UIImageView+WebCache.h>
#import <DKNightVersion.h>

#define WIDTH self.frame.size.width

@interface TableViewCellOfTwo ()

@property (nonatomic ,retain)UILabel *label;
@property (nonatomic ,retain)UIImageView *imageViewPic;
@property (nonatomic ,retain)UIImageView *imageViewOfTwo;
@property (nonatomic ,retain)UIImageView *imageViewOfThree;

@end

@implementation TableViewCellOfTwo



- (void)dealloc {

    [_label release];
    [_imageViewPic release];
    [_imageViewOfTwo release];
    [_imageViewOfThree release];
    [super dealloc];

}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {


    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createLabel];
        [self createimage];
        
    }

    return self;
}



- (void)createLabel {

    self.label = [[UILabel alloc] init];
    [self.contentView addSubview:self.label];
    [self.label release];
    self.label.numberOfLines = 0;
    self.label.textAlignment = 1;
    self.label.dk_textColorPicker = DKColorWithColors([UIColor colorWithWhite:0.247 alpha:1.000],[UIColor whiteColor]);
}




- (void)passModelWithPic:(PictureModel *)model {
    self.label.text = model.title;

    [model.imageurls[0] objectForKey:@"url"];
   NSString *str1 =  [self Substring:[model.imageurls[0] objectForKey:@"url"]];
    [self.imageViewPic sd_setImageWithURL:[NSURL URLWithString:str1]];
    
   
   NSString *str2 =  [self Substring: [model.imageurls[1]  objectForKey:@"url"]];
    [self.imageViewOfTwo sd_setImageWithURL:[NSURL URLWithString:str2]];
    
    
    NSString *str3 = [self Substring:[model.imageurls[2] objectForKey:@"url"]];
    [self.imageViewOfThree sd_setImageWithURL:[NSURL URLWithString:str3]];

    

}

#pragma mark - 图片Url截取
- (NSString *)Substring:(NSString *)urlString {
    
    
    NSString *sub = urlString;
    
    if ([sub isEqualToString:@""]) {
        return nil;
    }
    
    if ([sub hasSuffix:@"jpg"]) {
        return urlString;
    }
    else {
        
        NSRange range = [urlString rangeOfString:@"u="];
        
        NSString *sub1 = [urlString substringFromIndex:range.location+2];
        
        NSRange lastRange = [sub1 rangeOfString:@"&"];
        sub = [sub1 substringToIndex:lastRange.location];
        
    }
    
    return sub;
}





- (void)createimage {

    self.imageViewPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    [self.contentView addSubview:self.imageViewPic];
    [self.imageViewPic release];


    self.imageViewOfTwo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    [self.contentView addSubview:self.imageViewOfTwo];
    [self.imageViewOfTwo release];

    self.imageViewOfThree = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    [self.contentView addSubview:self.imageViewOfThree];
    [self.imageViewOfThree release];

}









- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.label.frame = CGRectMake(10, 5, self.frame.size.width - 20, 40);

    
    
    self.imageViewPic.frame = CGRectMake(10, 35, (WIDTH - 40),self.frame.size.height/3 *2  -40);
    
    self.imageViewOfTwo.frame = CGRectMake(10 , self.frame.size.height / 3 * 2 , (WIDTH - 40 )/2 -5,self.frame.size.height / 3);
    
    self.imageViewOfThree.frame = CGRectMake(WIDTH/2 -10 , self.frame.size.height / 3 * 2 , (WIDTH - 40)/2,self.frame.size.height / 3);
    
    
}








- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
